home *** CD-ROM | disk | FTP | other *** search
/ ETO Development Tools 2 / ETO Development Tools 2.iso / Tools - Objects / MacApp / MacApp CD Release / MacApp 2.0.1 (Many Libraries) / Libraries / UMemory.a < prev    next >
Encoding:
Text File  |  1990-10-25  |  4.3 KB  |  125 lines  |  [TEXT/MPS ]

  1. ;=============================================================================
  2. ; UMemory assembly language routines
  3. ;
  4. ; Copyright © 1987-1990 Apple Computer, Inc.  All rights reserved.
  5. ;
  6.                 Blanks        On
  7.                 String        AsIs
  8.                 Case        On
  9.  
  10.                 Print        Off
  11.                 Include     'Macros.a'
  12.         If not qNeedsROM128K then
  13.                 INCLUDE        'SysEqu.a'
  14.                 INCLUDE        'Traps.a'
  15.         endif
  16.  
  17.                 LOAD            'ProgStrucMacs.d'
  18.                 LOAD            'FlowCtlMacs.d'
  19.                 Print        On
  20.  
  21.             
  22. ;---------------------------------------------------------------------------------------------------
  23. ;    PROCEDURE ALoadMacAppSeg;
  24. ;    This is the actual patch for LoadSeg.  It sets up the stack so that we
  25. ;    can call FUNCTION LoadMacAppSegment (segNum: INTEGER): LONGINT.
  26.  
  27.                 Seg         'MAMemoryRes'
  28. EXPORT PROCEDURE ALOADMACAPPSEG(theSegNum:W)
  29.  
  30.     BEGIN    Save=D0-D2/A0-A2
  31.     IMPORT    LOADMACAPPSEGMENT, POSTLOADMACAPPSEGMENT
  32.  
  33.                 CALL        LOADMACAPPSEGMENT:L(theSegNum(FP):W),A0
  34.  
  35.                 Move.W        theSegNum(FP),-(SP)            ; push the original parameter to loadseg
  36.                 PEA            ComeBack+6                    ; push a return address
  37.                                                         ; loadseg will knock 6 off the return address
  38.                 Jmp            (A0)                        ; Call the original loadseg
  39.  
  40. ComeBack
  41.                 CALL         POSTLOADMACAPPSEGMENT        ; call back to Pascal again
  42.  
  43.                 Sub.L            #6,4(FP)                ; jerk our return address just like loadseg does
  44. ;                Return                                     ; Return to the real world
  45. ; the Return macro doesn't preserve the A0 register because it generates the following code
  46.  
  47. ;00000026: 4CDF 0707      'L...'            MOVEM.L    (A7)+,D0-D2/A0-A2
  48. ;0000002A: 4E5E           'N^'              UNLK       A6
  49. ;0000002C: 205F           ' _'              MOVEA.L    (A7)+,A0
  50. ;0000002E: 544F           'TO'              ADDQ.W     #$2,A7
  51. ;00000030: 4ED0           'N.'              JMP        (A0)
  52.  
  53. ; So… we'll just have to take over from the computers and land this puppy by hand
  54.  
  55.                 MOVEM.L    (A7)+,D0-D2/A0-A2
  56.                 UNLK       A6
  57.                 MOVE.L    (A7),2(A7)        ; move the return address into the place of the
  58.                                             ; parameter because we will destroy the stack-frame
  59.                                             ; that includes the parameter and then just RTS
  60.                                             ; This assumes intimate knowledge (!) of the fact that
  61.                                             ; this function only has a single parameter that is
  62.                                             ; an integer (2 bytes)
  63.                 ADDQ.W     #$2,A7            ; Destroy the stack frame just like I told you
  64.                 RTS                            ; We're outta here with A0 preserved
  65.                 EndP
  66.  
  67. ;---------------------------------------------------------------------------------------------------
  68. ;    FUNCTION PreLoadSegment;
  69. ;    This function preloads a segment in both the resource manager sense and the
  70. ;    segment loader sense.
  71.  
  72.                 Seg         'MAMemoryRes'
  73. EXPORT FUNCTION PRELOADSEGMENT(theSegNum:W):B
  74.  
  75.     BEGIN    Save=D0-D2/A0-A2
  76.     IMPORT    PRELOADSEGMENTRESOURCE, LOADMACAPPSEGMENT, POSTLOADMACAPPSEGMENT
  77.     ; preload the resource so our call to the seg loader patch won't fail
  78.  
  79.                 CALL        PRELOADSEGMENTRESOURCE:B(theSegNum(FP):W),D0
  80.                 TST.B        D0
  81.                 BNZ.S        success
  82.     ;segment didn't load
  83.     
  84.                 Move.B        #0, PRELOADSEGMENT(FP)
  85.                 BRA.S        exit
  86.     
  87.  
  88. success
  89.                 CALL        LOADMACAPPSEGMENT:L(theSegNum(FP):W),A0
  90.  
  91. ;thank-you François Grieu
  92.         If not qNeedsROM128K then
  93.                 TST.W        ROM85
  94.                 BPL.S        @dontFixIt                ; if it isn't broken…
  95.                 MOVE.L        A0,-(A7)                ; save old _LoadSeg address
  96.                 SUBQ.L        #4,A7                    ; make some room for _GetResourceresult
  97.                 MOVE.L        #'CODE',-(A7)            ; get the CODE resource (once more…)
  98.                 MOVE.W        theSegNum(FP),-(SP)        ; push the segment number
  99.                 _GetResource                        ; this can't fail, it has just been checked
  100.                 MOVE.L        (A7)+,A0                ; handle to the code resource
  101.                 MOVE.L        (A0),A0                    ; points to first word of the code resource
  102.                 MOVE.W        (A0),D0                    ; offset of first entry in the jump table
  103.                 LEA            2(A5,D0.W),A0            ; the offset thou shall use shall be two
  104.                 ADD.W        CurJTOffset,A0            ; points to the first routine entry point
  105.                 CMPI.W        #$4EF9,(A0)                ; is it a JMP.L  ?
  106.                 MOVEA.L        (A7)+,A0                ; restore old _LoadSeg address
  107.                 BEQ.S        ComeBack                ; the segment is already loaded
  108. @dontFixIt
  109.         endif
  110.  
  111.                 Move.W        theSegNum(FP),-(SP)            ; push the original parameter to loadseg
  112.                 PEA            ComeBack+6                    ; push a return address
  113.                                                         ; loadseg will knock 6 off the return address
  114.                 Jmp            (A0)                        ; Call the original loadseg
  115.  
  116. ComeBack
  117.                 CALL         POSTLOADMACAPPSEGMENT        ; call back to Pascal again
  118.  
  119.  
  120.                 Move.B        #1, PRELOADSEGMENT(FP)
  121. exit
  122.                 Return                                     ; Return to the real world
  123.  
  124.                 END
  125.